package app.v1.wdt.mapper;

import app.v1.wdt.domain.pojo.WdtSalesOrderIdGenerator;
import com.gitee.feizns.quickstart.mybatis.plus.QuickstartBaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;

/**
 * wdt销售订单变化生成器
 * @author feizns
 * @since 2023/07/19
 */
@Mapper
public interface WdtSalesOrderIdGeneratorMapper extends QuickstartBaseMapper<WdtSalesOrderIdGenerator> {

    /**
     * 下一个编号
     * @param shopNo 商店编号
     * @param warehouseNo 仓库没有
     * @param date 日期
     * @return {@link Long}
     */
    @Select("SELECT next_id FROM wdt_sales_order_id_generator WHERE shop_no = #{shopNo} AND warehouse_no = #{warehouseNo} AND date = #{date}")
    Long nextId(@Param("shopNo") String shopNo, @Param("warehouseNo") String warehouseNo, @Param("date") LocalDate date);

    /**
     * +下一个编号
     * @param shopNo 商店编号
     * @param warehouseNo 仓库没有
     * @param date 日期
     */
    @Update("UPDATE wdt_sales_order_id_generator SET next_id = next_id + 1 WHERE shop_no = #{shopNo} AND warehouse_no = #{warehouseNo} AND date = #{date}")
    void plusNextId(@Param("shopNo") String shopNo, @Param("warehouseNo") String warehouseNo, @Param("date") LocalDate date);

    /**
     * 根据日期删除指定的编号数据
     * @param date {@link LocalDate}
     */
    @Delete("DELETE FROM wdt_sales_order_id_generator WHERE date = #{date}")
    void deleteByDate(@Param("date") LocalDate date);

}
